ucount: Make get_ucount a safe get_user replacement
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 24 Jan 2022 18:46:50 +0000 (12:46 -0600)
committerSalvatore Bonaccorso <carnil@debian.org>
Sun, 30 Jan 2022 10:14:49 +0000 (10:14 +0000)
commit093e0339ee779ac10d87d8dace61961165a813cb
tree4c97746b11b95a2e96d1c423fb4a3f4b33247657
parent10733d106987192a468d6ccd4e9399ef9691c97d
ucount:  Make get_ucount a safe get_user replacement

Origin: https://git.kernel.org/linus/f9d87929d451d3e649699d0f1d74f71f77ad38f5
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2022-24122

When the ucount code was refactored to create get_ucount it was missed
that some of the contexts in which a rlimit is kept elevated can be
the only reference to the user/ucount in the system.

Ordinary ucount references exist in places that also have a reference
to the user namspace, but in POSIX message queues, the SysV shm code,
and the SIGPENDING code there is no independent user namespace
reference.

Inspection of the the user_namespace show no instance of circular
references between struct ucounts and the user_namespace.  So
hold a reference from struct ucount to i's user_namespace to
resolve this problem.

Link: https://lore.kernel.org/lkml/YZV7Z+yXbsx9p3JN@fixkernel.com/
Reported-by: Qian Cai <quic_qiancai@quicinc.com>
Reported-by: Mathias Krause <minipli@grsecurity.net>
Tested-by: Mathias Krause <minipli@grsecurity.net>
Reviewed-by: Mathias Krause <minipli@grsecurity.net>
Reviewed-by: Alexey Gladkov <legion@kernel.org>
Fixes: d64696905554 ("Reimplement RLIMIT_SIGPENDING on top of ucounts")
Fixes: 6e52a9f0532f ("Reimplement RLIMIT_MSGQUEUE on top of ucounts")
Fixes: d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Cc: stable@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name ucount-Make-get_ucount-a-safe-get_user-replacement.patch
kernel/ucount.c